<template>
	<view  :style="{height:screenHeight}">
		456
		<u-button text="月落" @click="submit"></u-button>
		<u-button text="登录" color="linear-gradient(to right, #3dbdad, #00b6d1)" @click="submit"></u-button>
		123
	</view>
</template>

<script>
	import api from '../api.js'
	export default {
		data() {
			return {
				screenHeight:this.$store.screenHeight
			};
		},
		methods:{
			submit(){
				var that = this
				uni.getUserProfile({
					desc:"获取你的昵称、头像",
					success(res) {
						if(res.errMsg == "getUserProfile:ok" && res.userInfo != undefined){
							var userInfo = {
								avatarUrl:res.userInfo.avatarUrl,
								nickName:res.userInfo.nickName
							}
							that.getUserOpenId(userInfo)
						}
					},
					complete(res) {
						console.log(res);
					}
				})
			},
			getUserOpenId(userInfo){
				var that = this
				uni.login({
					provider:'weixin',
					success(res) {
						that.login(res.code)
					}
				})
			},
			async login(code){
				var result = await api.LoginByWeChat(code)
				console.log(result);
			}
		}
	}
</script>

<style lang="scss">

</style>
